package com.taobao.analyse.map;

import java.io.IOException;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

import com.taobao.analyse.constants.AuctionAuctionsPosConstants;
import com.taobao.analyse.constants.SplitConstants;

public class ItemPriceSourceMapper extends MapReduceBase implements
		Mapper<Writable, Text, LongWritable, Text> {

	@Override
	public void map(Writable key, Text value,
			OutputCollector<LongWritable, Text> output, Reporter reporter)
			throws IOException {
		String line = value.toString();
		String[] aa = StringUtils.splitPreserveAllTokens(line, SplitConstants.ITEM_REGX);
		if(aa.length < 65 ){
			return;
		}
		String itemid = aa[AuctionAuctionsPosConstants.AUCTION_ID];
		String price = aa[AuctionAuctionsPosConstants.AUCTION_PRICE];
		if(StringUtils.isEmpty(itemid)||StringUtils.isEmpty(price)){
			return;
		}
		try{
			output.collect(new LongWritable(Long.parseLong(itemid)),new Text(buildPriceInfo(price)));
		}catch(Exception e){
			
		}
	}

	private String buildPriceInfo(String price) {
		return "price:"+price;
	}

}
